package com.neuedu.service.impl;

import com.neuedu.domain.OrderItem;
import com.neuedu.domain.Orders;
import com.neuedu.domain.Products;
import com.neuedu.mapper.WebOrdersMapper;
import com.neuedu.service.WebOrdersService;
import org.omg.PortableInterceptor.INACTIVE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ercai
 * @date 2019/8/5 - 18:22
 */
@Service
public class WebOrdersServiceImpl implements WebOrdersService {

    @Autowired
    private WebOrdersMapper webOrdersMapper;

    public Products findBook(Integer id) {

        return webOrdersMapper.findBook(id);
    }

    public void createOrder(Orders order) {

        //1.添加订单到数据库
        webOrdersMapper.addOrder(order);

        //2.添加订单详情到数据库
        webOrdersMapper.addOrderItem(order.getOrderItems());

        //3.减库存
        webOrdersMapper.deletePnum(order.getOrderItems());
    }

    public List<Orders> findOrderById(Integer id) {
        return webOrdersMapper.findOrderById(id);
    }

    public Orders findOrderByOrderId(String id) {

        return webOrdersMapper.findOrderByOrderId(id);
    }

    public void deleteOrderByOrderId(String id) {

        //通过orderid查询到order


        //遍历order的订单详情orderItem，恢复库存，然后删除orderItem


        //全部恢复库存，删除orderItem后，删除order
    }
}
